package com.akeil.flash.labelprovider;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import com.akeil.flash.model.ExData;
import com.akeil.flash.pojo.Data;

import flash.Activator;

public class ExDataLabelProvider extends LabelProvider implements
		ITableLabelProvider {
	DecimalFormat df1 = new DecimalFormat("0.00");
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	Calendar calendar = Calendar.getInstance();

	@Override
	public String getColumnText(Object element, int columnIndex) {
		// TODO Auto-generated method stub
		// { "序号", "样品名称", "样品编号","样品密度", "样品体积", "S标线", "S积分数", "S含量", "N标线", "N积分数", "N含量", "测试时间" };
		ExData exdata = (ExData) element;
		Data data = exdata.getData();
		if(data.getStatus() != 3){
			if (columnIndex == 0) {
				return String.valueOf(1);
			}else if (columnIndex == 1) {
				return data.getSamplename();
			}else if (columnIndex == 2) {
				return data.getSampleno();
			}else if (columnIndex == 3) {
				return df1.format(data.getPretemperature());
			} else if (columnIndex == 4) {
				return df1.format(data.getFlashtemperature());
			}else if (columnIndex == 5) {
				return data.getTesttime();
			}
		}else{//分组信息
			if(columnIndex == 0){
				return "分组";
			}else if (columnIndex == 1) {
				return data.getSamplename();
			}else if (columnIndex == 2) {
				return data.getSampleno();
			}else if (columnIndex == 3) {
				return df1.format(data.getPretemperature());
			} else if (columnIndex == 4) {
				return df1.format(data.getFlashtemperature());
			}else if (columnIndex == 5) {
				return data.getTesttime();
			}
		}

		return null;
	}

	public Image getColumnImage(Object obj, int index) {
		ExData exdata = (ExData) obj;
		Data data = exdata.getData();
		if(data.getStatus() != 3){
			if (index == 0) {
				return AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/data/sample_16px.png").createImage();
			}
		}else{
			if (index == 0) {
				return AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/data/group_16px.png").createImage();
			}
		}
		return null;
	}

	public Image getImage(Object obj) {
		return PlatformUI.getWorkbench().getSharedImages()
				.getImage(ISharedImages.IMG_OBJ_ELEMENT);
	}
}